import 'package:flutter/material.dart';

class ButtonPage extends StatefulWidget {
  @override
  _ButtonPageState createState() => new _ButtonPageState();
}

class _ButtonPageState extends State<ButtonPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Button"),
      ),
      body: _buildListView(),
    );
  }

  Widget _buildListView() {
    return ListView.builder(
      itemBuilder: (context, index) {
        return _buildListViewItem(index);
      },
      itemCount: buttons.length,
    );
  }

  Widget _buildListViewItem(index) {
    return Container(
      padding: EdgeInsets.all(10.0),
      alignment: Alignment.center,
      child: buttons[index],
    );
  }
}

var _dropValue = '语文';

List<Widget> buttons = <Widget>[
  Column(
    children: <Widget>[
      Text("RaisedButton"),
      Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            RaisedButton(
              child: Text("Gnerv"),
              onPressed: () {},
            ),
            RaisedButton(
              child: Text("Gnerv"),
              color: Colors.blue,
              onPressed: () {},
            ),
            RaisedButton(
              child: Text("Gnerv"),
              elevation: 5.0,
              highlightElevation: 5.0,
              disabledElevation: 5.0,
              onPressed: () {},
            ),
          ],
        ),
      ),
      Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            RaisedButton(
              child: Text("Gnerv"),
              disabledColor: Colors.white70,
              splashColor: Colors.blue,
              onPressed: () {},
            ),
            RaisedButton(
              child: Text("Gnerv"),
              disabledTextColor: Colors.blue,
            ),
            RaisedButton(
              child: Text("Gnerv"),
              highlightColor: Colors.blue,
              onPressed: () {},
            ),
          ],
        ),
      ),
    ],
  ),
  Column(
    children: <Widget>[
      Text("FlatButton"),
      Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            FlatButton(
              child: Text("Gnerv"),
              onPressed: () {},
            ),
            FlatButton(
              child: Text("Gnerv"),
              color: Colors.blue,
              onPressed: () {},
            ),
            FlatButton(
              child: Text("Gnerv"),
              onPressed: () {},
            ),
          ],
        ),
      ),
      Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            FlatButton(
              child: Text("Gnerv"),
              disabledColor: Colors.white70,
              splashColor: Colors.blue,
              onPressed: () {},
            ),
            FlatButton(
              child: Text("Gnerv"),
              disabledTextColor: Colors.blue,
            ),
            FlatButton(
              child: Text("Gnerv"),
              highlightColor: Colors.blue,
              onPressed: () {},
            ),
          ],
        ),
      ),
    ],
  ),
  Column(
    children: <Widget>[
      Text("OutlineButton"),
      Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            OutlineButton(
              child: Text("Gnerv"),
              onPressed: () {},
            ),
            OutlineButton(
              child: Text("Gnerv"),
              color: Colors.blue,
              onPressed: () {},
            ),
            OutlineButton(
              child: Text("Gnerv"),
              highlightElevation: 5.0,
              onPressed: () {},
            ),
          ],
        ),
      ),
      Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            OutlineButton(
              child: Text("Gnerv"),
              splashColor: Colors.blue,
              onPressed: () {},
            ),
            OutlineButton(
              child: Text("Gnerv"),
              disabledTextColor: Colors.blue,
            ),
            OutlineButton(
              child: Text("Gnerv"),
              highlightColor: Colors.blue,
              onPressed: () {},
            ),
          ],
        ),
      ),
    ],
  ),
  Column(
    children: <Widget>[
      Text("DropdownButton"),
      Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            DropdownButton(
              value: _dropValue,
              items: [
                DropdownMenuItem(
                  child: Text('语文'),
                  value: '语文',
                ),
                DropdownMenuItem(child: Text('数学'), value: '数学'),
                DropdownMenuItem(child: Text('英语'), value: '英语'),
              ],
              onChanged: (value) {
                _dropValue = value;
              },
            ),
            DropdownButton(
              hint: Text('请选择'),
              items: [
                DropdownMenuItem(
                  child: Text('语文'),
                  value: '语文',
                ),
                DropdownMenuItem(child: Text('数学'), value: '数学'),
                DropdownMenuItem(child: Text('英语'), value: '英语'),
              ],
              onChanged: (value) {
                _dropValue = value;
              },
            ),
          ],
        ),
      ),
    ],
  ),
  Column(
    children: <Widget>[
      Text("PopupMenuButton"),
      Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            PopupMenuButton<String>(
              itemBuilder: (context) {
                return <PopupMenuEntry<String>>[
                  PopupMenuItem<String>(
                    value: '语文',
                    child: Text('语文'),
                  ),
                  PopupMenuItem<String>(
                    value: '数学',
                    child: Text('数学'),
                  ),
                  PopupMenuItem<String>(
                    value: '英语',
                    child: Text('英语'),
                  ),
                  PopupMenuItem<String>(
                    value: '生物',
                    child: Text('生物'),
                  ),
                  PopupMenuItem<String>(
                    value: '化学',
                    child: Text('化学'),
                  ),
                ];
              },
            ),
            PopupMenuButton<String>(
              tooltip: 'PopupMenuButton',
              itemBuilder: (context) {
                return <PopupMenuEntry<String>>[
                  PopupMenuItem<String>(
                    value: '语文',
                    child: Text('语文'),
                  ),
                  PopupMenuItem<String>(
                    value: '数学',
                    child: Text('数学'),
                  ),
                  PopupMenuItem<String>(
                    value: '英语',
                    child: Text('英语'),
                  ),
                  PopupMenuItem<String>(
                    value: '生物',
                    child: Text('生物'),
                  ),
                  PopupMenuItem<String>(
                    value: '化学',
                    child: Text('化学'),
                  ),
                ];
              },
            ),
            PopupMenuButton<String>(
              initialValue: '语文',
              itemBuilder: (context) {
                return <PopupMenuEntry<String>>[
                  PopupMenuItem<String>(
                    value: '语文',
                    child: Text('语文'),
                  ),
                  PopupMenuItem<String>(
                    value: '数学',
                    child: Text('数学'),
                  ),
                  PopupMenuItem<String>(
                    value: '英语',
                    child: Text('英语'),
                  ),
                  PopupMenuItem<String>(
                    value: '生物',
                    child: Text('生物'),
                  ),
                  PopupMenuItem<String>(
                    value: '化学',
                    child: Text('化学'),
                  ),
                ];
              },
            ),
          ],
        ),
      ),
      Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            PopupMenuButton<String>(
              elevation: 5,
              padding: EdgeInsets.all(5),
              color: Colors.red,
              itemBuilder: (context) {
                return <PopupMenuEntry<String>>[
                  PopupMenuItem<String>(
                    value: '语文',
                    child: Text('语文'),
                  ),
                  PopupMenuItem<String>(
                    value: '数学',
                    child: Text('数学'),
                  ),
                  PopupMenuItem<String>(
                    value: '英语',
                    child: Text('英语'),
                  ),
                  PopupMenuItem<String>(
                    value: '生物',
                    child: Text('生物'),
                  ),
                  PopupMenuItem<String>(
                    value: '化学',
                    child: Text('化学'),
                  ),
                ];
              },
            ),
            PopupMenuButton<String>(
              tooltip: 'PopupMenuButton',
              icon: Icon(Icons.add),
              itemBuilder: (context) {
                return <PopupMenuEntry<String>>[
                  PopupMenuItem<String>(
                    value: '语文',
                    child: Text('语文'),
                  ),
                  PopupMenuItem<String>(
                    value: '数学',
                    child: Text('数学'),
                  ),
                  PopupMenuItem<String>(
                    value: '英语',
                    child: Text('英语'),
                  ),
                  PopupMenuItem<String>(
                    value: '生物',
                    child: Text('生物'),
                  ),
                  PopupMenuItem<String>(
                    value: '化学',
                    child: Text('化学'),
                  ),
                ];
              },
            ),
            PopupMenuButton<String>(
              shape: RoundedRectangleBorder(
                  side: BorderSide(
                      color: Colors.red
                  ),
                  borderRadius: BorderRadius.circular(10)
              ),
              initialValue: '语文',
              itemBuilder: (context) {
                return <PopupMenuEntry<String>>[
                  PopupMenuItem<String>(
                    value: '语文',
                    child: Text('语文'),
                  ),
                  PopupMenuItem<String>(
                    value: '数学',
                    child: Text('数学'),
                  ),
                  PopupMenuItem<String>(
                    value: '英语',
                    child: Text('英语'),
                  ),
                  PopupMenuItem<String>(
                    value: '生物',
                    child: Text('生物'),
                  ),
                  PopupMenuItem<String>(
                    value: '化学',
                    child: Text('化学'),
                  ),
                ];
              },
            ),
          ],
        ),
      ),
    ],
  ),

  Column(
    children: <Widget>[
      Text("BackButton"),
      Text("点击时默认执行Navigator.maybePop即如果路由栈有上一页则返回到上一页。"),
      Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            BackButton(),
          ],
        ),
      ),
    ],
  ),
  Column(
    children: <Widget>[
      Text("CloseButton"),
      Text("点击时默认执行Navigator.maybePop即如果路由栈有上一页则返回到上一页。"),
      Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            CloseButton(),
          ],
        ),
      ),
    ],
  ),
  Column(
    children: <Widget>[
      Text("ButtonBar"),
      Container(
        child: Column(
          children: <Widget>[
            ButtonBar(
              children: <Widget>[
                RaisedButton(),
                RaisedButton(),
                RaisedButton(),
                RaisedButton(),
              ],
            ),
            ButtonBar(
              alignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
                RaisedButton(),
                RaisedButton(),
                RaisedButton(),
                RaisedButton(),
              ],
            ),
          ],
        ),
      ),
    ],
  ),
];
